﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Business_Logic_Layer;

namespace Money_Dance
{
    public partial class UserControlTransactionRemider : UserControl
    {
        BUSS Buss = new BUSS();
        int AutoCommit = 0;
        DateTime date = DateTime.Now;
        public static string AccountType;
        public static int UserID;  

        public UserControlTransactionRemider()
        {
            InitializeComponent();
        }
        /// <summary>
        /// Constructor UserControlTransactionRemider.
        /// </summary>
        /// <param name="AccID"></param>
        /// <param name="UserId"></param>
        public UserControlTransactionRemider(string AccID, int UserId)
        {
            AccountType = AccID;
            UserID = UserId;
        }      

        private void btn_Capnhat_Click(object sender, EventArgs e)
        {             
            // Đưa nội dung lịch nhắc vào bảng Timerule và TransactionReminger.
            Buss.InsertTimerule(txtStartDate.Text, txtEndDate.Text, More.Text, txtRepeatValues.Text, int.Parse(txtRepeatSeed.Text));
            Buss.InsertTransReminder(Buss.GetIdAccount(UserID, AccountType), double.Parse(TbxSoTienChi.Text), double.Parse(TbxSoTienThu.Text), Buss.GetIdCategory(CbbCategory.Text), Description.Text, AutoCommit, (int)Buss.GetIDTimer());
            // Show các lịch nhắc vừa tạo.
            dataGridViewChecking.DataSource = Buss.TransReminder(UserID, AccountType);           
        } 

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            AutoCommit = 1;
        }

        private void UserControlTransactionRemider_Load(object sender, EventArgs e)
        {
            // Đưa dữ liệu danh mục trong bảng Category ra Combobox.
            CbbCategory.DataSource=Buss.Categories();
            CbbCategory.DisplayMember = "NAME";
            CbbCategory.ValueMember = "NAME";
            // Show lịch nhắc nhở.
            dataGridViewChecking.DataSource = Buss.TransReminder(UserID, AccountType);
            txtStartDate.Text = date.ToShortDateString();
        }

        private void TbxSoTienChi_Click(object sender, EventArgs e)
        {
            TbxSoTienChi.Clear();
            TbxSoTienThu.Text = "0";
        }

        private void TbxSoTienThu_Click(object sender, EventArgs e)
        {
            TbxSoTienThu.Clear();
            TbxSoTienChi.Text = "0";
        }
    }
}
